import { Body, Controller, Get, Inject, Post, Query, UsePipes } from "@nestjs/common";
import { ApiOperation, ApiTags } from "@nestjs/swagger";
import { query } from "express";
import { Validate_Mods } from "src/common/enum/ValidateModsEnum";
import { PageQuery } from "src/common/page/PageQuery";
import { PageResult } from "src/common/page/PageResult";
import { MyValidationPipe } from "src/common/pipe/MyValidationPipe";
import { Result } from "src/common/Result";
import { GoodsDto } from "src/dto/GoodsDto";
import { Goods } from "src/entity/Goods";
import { GoodsService } from "src/service/GoodsService";

@ApiTags("商品模块")
@Controller("/goods")
export class GoodsController {
    @Inject()
    private goodsService: GoodsService;

    /**
     * 添加商品
     * @param dto 
     */
    @ApiOperation({summary: "添加商品"})
    @UsePipes(new MyValidationPipe([Validate_Mods.create]))
    @Post("/addGoods")
    async addGoods(@Body() dto: GoodsDto) {
        return await this.goodsService.addGoods(dto);
    }

    /**
     * 商品列表查询
     * @param query 
     * @returns 
     */
    @ApiOperation({summary: "商品列表查询"})
    @Post("/selectList")
    async selectList(@Body() query: PageQuery<GoodsDto>) {
        let data = await this.goodsService.selectList(query);
        return Result.success("成功", PageResult.of(data))
    }

     /**
      * 商品详情查询
      * @param query 
      */
     @ApiOperation({summary: "商品详情查询"})
     @UsePipes(new MyValidationPipe([Validate_Mods.detail]))
     @Get("/goodsQuery")
    async goodsQuery(@Query() query: GoodsDto) {
       let data = await this.goodsService.goodsQuery(query);
       return Result.success("成功", data);
    }

    /**
     * 商品删除
     * @param dto 
     */
    @ApiOperation({summary: "商品删除"})
    @Post("/remove")
    async remove(@Body() dto: GoodsDto) {
        return await this.goodsService.remove(dto)
    }

    /**
     * 商品更新
     */
    @ApiOperation({summary: "商品更新"})
    @Post("/update")
    async update(@Body() dto: GoodsDto) {
        return await this.goodsService.update(dto);
    }
}